import { defineStore } from 'pinia'

import { getBannerApi, getNewSongApi, getPersonalizedApi, getTopListApi } from '@renderer/api'

const useRecommed = defineStore('recommed', {
  state: () => ({
    bannerlist: [],
    personalizedList: [],
    newMusicList: [],
    rankingIds: [19723756, 3779629, 2884035, 3778678] as number[], // 排行榜id
    rankingList: [] as any[] // 排行榜数据
  }),
  actions: {
    // 获得轮播图列表
    async getBannerList() {
      const res: any = await getBannerApi()
      this.bannerlist = res.banners
    },
    // 获得推荐歌单
    async getRecommedList() {
      const res: any = await getPersonalizedApi(8)
      this.personalizedList = res.result
    },
    // 获得最新音乐
    async getNewMusicList() {
      const res: any = await getNewSongApi()
      this.newMusicList = res.result
    },
    // 获得排行榜数据
    getRankingList() {
      this.rankingIds.forEach(async (id) => {
        const res: any = await getTopListApi(id)
        const playlists = res.playlist
        this.rankingList.push(playlists)
      })
    }
  }
})

export default useRecommed
